<template>
  <div class="curr-page">
    <div>
      <el-descriptions class="mt-3" title="个人信息" :column="1" size="medium">
        <el-descriptions-item label="用户昵称">
          {{ user.username }}
        </el-descriptions-item>
        <el-descriptions-item label="创建时间">
          {{ dateFormatter(user.createdAt) }}
        </el-descriptions-item>
      </el-descriptions>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: {},
    };
  },

  methods: {
    fetchInitData() {
      this.fetchUser();
    },

    async fetchUser() {
      await this.$axios
        .get(`/user/infos/${sessionStorage.userId}`)
        .then((res) => {
          this.user = res.data;
        });
    },

    dateFormatter(cellValue) {
      let date = new Date(cellValue);
      const year = date.getFullYear().toString();
      const month = date
        .getMonth()
        .toString()
        .padStart(2, "0");
      const day = date
        .getDate()
        .toString()
        .padStart(2, "0");
      let hours = date.getHours();
      let minutes = date.getMinutes();
      return year + "-" + month + "-" + day + " " + hours + ":" + minutes;
    },
  },

  created() {
    this.fetchInitData();
  },
};
</script>

<style lang="scss" scoped>
.curr-page {
  margin: 0px;
  padding: 0px;
}
</style>
